<?php
if($_GET['name']){
	$userMessage = $c->show_user_by_name($_GET['name']);
	if($userMessage["error_code"]){
		$userMessage = $c->show_user_by_id($_GET['name']);
		$userFriendsList = $c->friends_by_id($_GET['name'], 0, 8);
		$userFollowersList = $c->followers_by_id($_GET['name'], 0, 8);
	}
	else{
		$userFriendsList = $c->friends_by_name($_GET['name'], 0, 8);
		$userFollowersList = $c->followers_by_name($_GET['name'], 0, 8);
	}
}
else if($_GET['post']){
	$userMessage = $thistimeline["user"];
	$userName = $userMessage["screen_name"];
	$userId = $userMessage["id"];
	if($userName){
		$userFriendsList = $c->friends_by_name($userName, 0, 8);
		$userFollowersList = $c->followers_by_name($userName, 0, 8);
	}
	else{
		$userFriendsList = $c->friends_by_id($userId, 0, 8);
		$userFollowersList = $c->followers_by_id($userId, 0, 8);
	}
}
else{
	$userFriendsList = $c->friends_by_id($uid, 0, 8);
	$userFollowersList = $c->followers_by_id($uid, 0, 8);
}

$userid = $userMessage["id"];
$userName = $userMessage["screen_name"];
$userName = $userName?$userName:$userid;
$userHead = $userMessage["avatar_large"];
$userLocation = $userMessage["location"];
$userFriendsCount = $userMessage["friends_count"];
$userFollowersCount = $userMessage["followers_count"];
$userDescription = $userMessage["description"];
$userUrl = $userMessage["url"];
$userVerified = $userMessage["verified"];
if($uid!=$userid){
	$isme = false;
}
else{
	$isme = true;
}
?>
<div><img class="sideBarUserHead" src="<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($userHead):$userHead; ?>" /></div>
<div class="wUserName">
<?
if(!$_GET['name'] || isset($_GET['friendships'])){
	if($userVerified){
?>
<div class="verify" title="认证用户" alt="认证用户"></div>
<?php
	}
?>
<a href="/user/<?php echo $userName; ?>"><?php echo $userName; ?></a>
<?php	
}
else{
	if($userVerified){
?>
<div class="verify" title="认证用户" alt="认证用户"></div>
<?php
	}
	echo $userName;
}
?>
</div>

<?php if($userLocation){ ?>
<div class="wUserLocation" onmouseover="document.getElementById('mapdiv').style.display='block';" onmouseout="document.getElementById('mapdiv').style.display='none';">
<?php echo $userLocation; ?>
<div id="mapdiv"><img onerror="this.src='/images/maperror.png'" style="padding: 20px 10px 10px 10px; width: 200px; height: 150px;" src="//maps.google.com/maps/api/staticmap?zoom=2&size=200x150&markers=color:blue|<?php echo urlencode($userLocation); ?>&sensor=false" /></div>
</div>
<div class="wUserUrl"><a target="_blank" href="<?php echo $userUrl; ?>"><?php echo $userUrl; ?></a></div>
<div class="wUserDescription"><?php echo $userDescription; ?></div>
<?php
}
if(!$isme){
	$followed = $userMessage["following"];
	if($followed){
?>
<div class="followAction"><button class="unfollowButton" onclick="removeFriendInPage('<?php echo $userid; ?>',this);">取消关注</button></div>
<?php
	}
	else{
?>
<div class="followAction"><button class="followButton" onclick="follow('<?php echo $userid; ?>',this);">添加关注</button></div>
<?php
	}
}
?>

<div class="sideCube">
<div class="sideCubeTitle"><?php echo $isme?"我":($userMessage["gender"]=="m"?"他":($userMessage["gender"]=="f"?"她":"TA")); ?>关注的人（<?php echo $userFriendsCount; ?>）</div>
<div class="sideBarFriendsList">
<?php
$j = 0;
for($i=0; $i<count($userFriendsList["users"]) && $j<4; $i++){
	$userInfo = $userFriendsList["users"][$i];
	$userInfoName = $userInfo["screen_name"];
	$userInfoId = $userInfo["id"];
	$userInfoName = $userInfoName?$userInfoName:$userInfoId;
	if(!$userInfoName){
		continue;
	}
	$j++;
?>
<a href="/user/<?php echo $userInfoName; ?>"><img title="<?php echo $userInfoName; ?>" alt="<?php echo $userInfoName; ?>" class="sideBarFriendsHead" src="<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($userInfo["profile_image_url"]):$userInfo["profile_image_url"]; ?>" /></a>
<?php
}
?>
</div>
<div class="sideBarFriendsList">
<?php
for(; $i<count($userFriendsList["users"]) && $j<8; $i++){
	$userInfo = $userFriendsList["users"][$i];
	$userInfoName = $userInfo["screen_name"];
	$userInfoId = $userInfo["id"];
	$userInfoName = $userInfoName?$userInfoName:$userInfoId;
	if(!$userInfoName){
		continue;
	}
	$j++;
?>
<a href="/user/<?php echo $userInfoName; ?>"><img title="<?php echo $userInfoName; ?>" alt="<?php echo $userInfoName; ?>" class="sideBarFriendsHead" src="<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($userInfo["profile_image_url"]):$userInfo["profile_image_url"]; ?>" /></a>
<?php
}
?>
</div>
<div class="sideCubeMore"><a href="/friends<?php if($_GET["name"] && $uid!=$userid || $_GET["post"]){echo "/".$userName;} ?>">查看全部</a></div>
</div>

<div class="sideCube">
<div class="sideCubeTitle">关注<?php echo $isme?"我":($userMessage["gender"]=="m"?"他":($userMessage["gender"]=="f"?"她":"TA")); ?>的人（<?php echo $userFollowersCount; ?>）</div>
<div class="sideBarFriendsList">
<?php
$j = 0;
for($i=0; $i<count($userFollowersList["users"]) && $j<4; $i++){
	$userInfo = $userFollowersList["users"][$i];
	$userInfoName = $userInfo["screen_name"];
	$userInfoId = $userInfo["id"];
	$userInfoName = $userInfoName?$userInfoName:$userInfoId;
	if(!$userInfoName){
		continue;
	}
	$j++;
?>
<a href="/user/<?php echo $userInfoName; ?>"><img title="<?php echo $userInfoName; ?>" alt="<?php echo $userInfoName; ?>" class="sideBarFriendsHead" src="<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($userInfo["profile_image_url"]):$userInfo["profile_image_url"]; ?>" /></a>
<?php
}
?>
</div>
<div class="sideBarFriendsList">
<?php
for(; $i<count($userFollowersList["users"]) && $j<8; $i++){
	$userInfo = $userFollowersList["users"][$i];
	$userInfoName = $userInfo["screen_name"];
	$userInfoId = $userInfo["id"];
	$userInfoName = $userInfoName?$userInfoName:$userInfoId;
	if(!$userInfoName){
		continue;
	}
	$j++;
?>
<a href="/user/<?php echo $userInfoName; ?>"><img title="<?php echo $userInfoName; ?>" alt="<?php echo $userInfoName; ?>" class="sideBarFriendsHead" src="<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($userInfo["profile_image_url"]):$userInfo["profile_image_url"]; ?>" /></a>
<?php
}
?>
</div>
<div class="sideCubeMore"><a href="/followers<?php if($_GET["name"] && $uid!=$userid || $_GET["post"]){echo "/".$userName;} ?>">查看全部</a></div>
</div>